<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('已部署流程列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li>
								流程标识：<input type="text" name="key"/>
							</li>
							<li>
								流程名称：<input type="text" name="name"/>
							</li>
							<li>
								版本：<select name="latest">
											<option value="true" selected>只看最新版</option>
											<option value="false">全部版本</option>
										</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.modal.open('上传部署文件', '/flow/manage/deploy', '500', '250');">
					<i class="fa fa-plus"></i> 部署
				</a>
			</div>
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		$(function() {
		    var options = {
		        url:  "/flow/manage/getprocesslists",
				removeUrl: "/flow/manage/remove/{id}",
				//createUrl: "/flow/manage/deploy",
		        sortName: "processSort",
		        modalName: "流程",
		        columns: [{
		            checkbox: true
		        },
				{
					field: 'id',
					title: '流程定义ID'
				},
				{
					field: 'deploymentId',
					title: '流程部署ID',
					sortable: true
				},
		        {
		            field: 'key',
		            title: '流程定义key',
		            sortable: true
		        },
		        {
		            field: 'name',
		            title: '流程名称',
		            sortable: true
		        },
		        {
		            field: 'resourceName',
		            title: '流程资源定义',
		            sortable: true,
					formatter: function(value, row, index) {
						return $.table.tooltip(value);
					}
		        },
				{
					field: 'version',
					title: '版本号',
					sortable: true
				},
				{
					title: '详情',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-warning btn-xs" target="_blank" href="/flow/manage/showProcessDefinition/'+row.deploymentId+'/'+ row.resourceName +  '"><i class="fa fa-edit"></i>查看定义</a> ');
						actions.push('<a class="btn btn-success btn-xs" target="_blank" href="/flow/manage/showresource?pdid='+row.id +  '"><i class="fa fa-area-chart"></i>流程图</a> ');
						return actions.join('');
					}
				},
		        {
		            title: '操作',
		            align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						if (row.suspended == true)
						{
							actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="run(\'' + row.id + '\')"><i class="fa fa-plug"></i>激活</a> ');
						} else {
							actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="suspend(\'' + row.id + '\')"><i class="fa fa-bolt"></i>挂起</a> ');
						}
						actions.push('<a class="btn btn-primary btn-xs" href="#" onclick="model(\'' + row.id + '\')"><i class="fa fa-chrome"></i>转为模型</a> ');
						actions.push('<a class="btn btn-danger btn-xs" href="#" onclick="$.operate.remove(\'' + row.deploymentId + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
					}
		        }]
		    };
		    $.table.init(options);
		});

		function model(pdid) {
			$.get("/flow/manage/exchangeProcessToModel/" + pdid, function (data) {
				$.modal.alert("转换成功");
			});
		}

		function suspend(pdid) {
			$.modal.open('挂起流程定义', "/flow/manage/suspend?pdid=" + pdid, '780', '480');
		}

		function run(pdid) {
			$.modal.open('激活流程定义', "/flow/manage/activate?pdid=" + pdid, '780', '480');
		}
	</script>
</body>
</html>